package com.heima.controller.vm_service;

import com.heima.pojo.dto.SkuClassRequest;
import com.heima.pojo.vo.SkuClassPageVo;
import com.heima.pojo.vo.SkuClassVo;
import com.heima.service.SkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service/skuClass")
@Slf4j
public class SkuClassController {
    @Autowired
    private SkuService skuService;

    //新增商品分类
    @PostMapping
    public Boolean addSkuClass(@RequestBody SkuClassRequest requestBody) {
        log.info("新增商品分类{}" ,requestBody.getClassName());
        Boolean result = skuService.addSkuClass(requestBody.getClassName());
        return result;
    }

    //分类搜索
    @GetMapping("/search")
    public SkuClassPageVo getSkuClsList(@RequestParam Integer pageIndex,
                                        @RequestParam Integer pageSize,
                                        @RequestParam(required = false) String className){
        log.info("分类搜索参数：{} {} {}" ,pageIndex,pageSize,className);
        SkuClassPageVo skuClassPageVo =skuService.getSkuClsList(pageIndex,pageSize,className);
        return skuClassPageVo;
    }

    //修改商品分类名称
    @PutMapping("/{classId}")
    public Boolean updateSkuClsName(@PathVariable Integer classId,
                                    @RequestBody SkuClassRequest requestBody){
        log.info("修改商品分类名称 {}" ,requestBody.getClassName());

        return skuService.updateSkuClsName(classId,requestBody.getClassName());
    }

    //删除商品分类
    @DeleteMapping("/{classId}")
    public void deleteSkuCls(@PathVariable Integer classId){
        log.info("删除商品分类{}" ,classId);
        skuService.deleteSkuCls(classId);
    }

    //通过id查询商品分类基本信息
    @GetMapping("/{classId}")
    public SkuClassVo getSkuClsById(@PathVariable Integer classId){
        log.info("查询商品分类基本信息{}" ,classId);
        SkuClassVo skuClassVo = skuService.getSkuClsById(classId);
        return skuClassVo;
    }


}
